package com.example.demo.controller;



import com.example.demo.ServerResponse;
import com.example.demo.Service.IBannersService;
import com.example.demo.entity.Banners;
import com.example.demo.utils.PageResult;
import com.example.demo.utils.PassToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * bannersController
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/banners/system")
public class BannersController
{
    @Autowired
    private IBannersService bannersService;

    /**
     * 查询banners列表
     */
    @PassToken
    @GetMapping("/list")
    public ServerResponse list(Banners banners, @RequestParam( defaultValue = "1") int pageNum,@RequestParam( defaultValue = "5") int pageSize)
    {
        PageResult pageResult = bannersService.selectBannersList(banners,pageNum,pageSize);
        return ServerResponse.createBySuccess(200,pageResult,"查询成功");
    }
    /**
     * 获取banners详细信息
     */
    @GetMapping(value = "/{id}")
    public ServerResponse getInfo(@PathVariable("id") Long id)
    {
        Banners banners = bannersService.selectBannersById(id);
        return ServerResponse.createBySuccess(200,banners,"查询成功");
    }

    /**
     * 新增banners
     */

    @PostMapping
    public ServerResponse add(@RequestBody Banners banners)
    {
        int i = bannersService.insertBanners(banners);
        if (i>0){
            return ServerResponse.createBySuccess(200,"","添加成功");
        }else {
            return ServerResponse.createBySuccess(500,"","添加失败");
        }
    }
    /**
     * 修改banners
     */

    @PutMapping()
    public ServerResponse edit(@RequestBody Banners banners)
    {
        int i = bannersService.updateBanners(banners);
        if (i>0){
            return ServerResponse.createBySuccess(200,"","更新成功");
        }else {
            return ServerResponse.createBySuccess(500,"","更新失败");
        }
    }

    /**
     * 删除banners
     */
	@DeleteMapping("/{ids}")
    public ServerResponse remove(@PathVariable Long[] ids)
    {
        int i = bannersService.deleteBannersByIds(ids);
        if (i>0){
            return ServerResponse.createBySuccess(200,"","删除成功");
        }else {
            return ServerResponse.createBySuccess(500,"","删除失败");
        }
    }
}
